/**
 * Created by hps on 17-4-27.
 */
public class ArraySel {
    private long[] a;
    private int nElems;

    public ArraySel(int max) {
        a = new long[max];
        nElems = 0;
    }

    public void insert(long value) {
        a[nElems++] = value;
    }

    public void display() {
        for (int i = 0; i < nElems; i++) {
            System.out.print(a[i] + " ");
        }
        System.out.println();
    }

    private void swap(int i, int j) {
        long temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }

    public void selectSort() {
        int min;
        for(int i = 0; i < nElems - 1; i++) {
            min = i;
            for (int j = i + 1; j < nElems; j++)
                if(a[min] > a[j])
                    min = j;
            swap(min, i);
        }
    }
}
